<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/resources/modular/plugin/taglibs.jsp" %>
<!doctype html>
<head content="-优惠码">
    <%@ include file="/resources/modular/head/inside_head.jsp" %>
</head>
<body class="GC_Menu_6" name="GC_coupon">
<%@ include file="/resources/modular/plugin/mainMenu.jsp" %>
<div class="page">
    <%@ include file="/resources/modular/plugin/mainTopMenu.jsp" %>
    <div class="page_left">
        <ul class="combopage_leftu1">
            <li><a class="cur" href="javascript:;">未使用</a></li>
            <li><a href="javascript:;">已使用</a></li>
            <li><a href="javascript:;">已过期</a></li>
        </ul>
    </div>

    <div class="page_right">
        <div class="promocode_inner">
            <div class="promocode_unused">
                <span>优惠码</span>
                <span>未使用：${unusedList.size()} 张
                    <span id="promocode_daochubtn">导出</span>
                    <a id="exportDown" href="javascript:;" class="exportDown" style="display: none">下载</a>
                </span>
            </div>

            <ul class="promocode_ul">
                <c:forEach items="${unusedList}" var="data" varStatus="index">
                    <li class="promocode_unused">
                        <p><span>${index.count}</span><span>${data.coin} 币</span></p>
                        <p>优惠码：${data.discountcode}</p>
                        <p>有效期：<fmt:formatDate pattern="yyyy-MM-dd" value="${data.inTime}"/> ~
                            <fmt:formatDate pattern="yyyy-MM-dd" value="${data.outTime}"/></p>
                    </li>
                </c:forEach>
            </ul>
        </div>

        <div class="promocode_inner">
            <div class="promocode_unused">
                <span>优惠码</span>
                <span>已使用：${usedList.size()} 张</span>
            </div>
            <ul class="promocode_usedul">
                <c:forEach items="${usedList}" var="data" varStatus="index">
                    <li class="promocode_used">
                        <p><span>${index.count}</span><span>${data.coin} 币</span></p>
                        <p>优惠码：${data.discountcode}</p>
                        <p>使用场地：${data.address}</p>
                        <p>使用设备：${data.dtName}&nbsp;&nbsp;${data.deviceName}</p>
                        <p>使用时间：<fmt:formatDate type="both" dateStyle="long" timeStyle="long"
                                                value="${data.updateTime}"/></p>
                    </li>
                </c:forEach>
            </ul>
        </div>

        <div class="promocode_inner">
            <div class="promocode_unused">
                <span>优惠码</span>
                <span>已过期：${outList.size()} 张</span>
            </div>
            <ul class="promocode_ul">
                <c:forEach items="${outList}" var="data" varStatus="index">
                    <li class="promocode_outdate">
                        <p><span>${index.count}</span><span>${data.coin} 币</span></p>
                        <p>优惠码：${data.discountcode}</p>
                        <p>有效期：<fmt:formatDate pattern="yyyy-MM-dd" value="${data.inTime}"/> ~
                            <fmt:formatDate pattern="yyyy-MM-dd" value="${data.outTime}"/></p>
                    </li>
                </c:forEach>
            </ul>
        </div>
    </div>
</body>

<script type="application/javascript">
    $(".page_right .promocode_inner:not(:first)").hide();
    $(".combopage_leftu1 a").each(function (index) {
        $(this).click(function () {
            $(this).addClass("cur").parent("li").siblings().children("a").removeClass("cur");
            $(".page_right .promocode_inner:eq(" + index + ")").stop().show().siblings().stop().hide();
        })
    })

    function doTime(){
        exportData();
        $("#promocode_daochubtn").text("导出").css("background","#38adff").css('display','none');
        $("#exportDown").css('display','');
    }

    exportData();

    function exportData(){
        $("#promocode_daochubtn").click(function () {
            $.ajax({
                url: "${basePath}v2/promocode/export",
                type: 'POST',
                error: function (response) {
                    $errorMsg(response);
                },
                success: function (ret) {
                    if(ret.result==true){
                        $("#promocode_daochubtn").unbind("click");
                        setTimeout(doTime, 1000*5);
                        $("#promocode_daochubtn").text("数据生成").css("background","#CCC");
                        var exportTemp = ret.exportId;
                        $("#exportDown").attr("href","${basePath}v2/promocode/exportDown/"+exportTemp);
                    }else{
                        alert(ret.info);
                    }
                }
            });
        });
    }

</script>

</html>
<%@ include file="/resources/modular/foot/inside_footer.jsp" %>
